
package com.av.torrent;

import com.av.torrent.helpers.PreferencesHelper;
import com.av.torrent.jobs.manager.DefaultJobManager;
import com.av.torrent.jobs.manager.JobManager;

import android.content.res.Configuration;
import android.util.Log;

/**
 * @author Uladzimir_Kerus
 */
public class Application extends android.app.Application {

  private static final String LOG_TAG = Application.class.getSimpleName();

  private static Application sInstance = null;

  private JobManager mJobManager;

  private PreferencesHelper mPreferencesHelper;

  
  	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Application#onCreate()
	 */
  @Override
  public void onCreate() {
    super.onCreate();
    Log.d(LOG_TAG, "In onCreate() : Initialization started...");
    initialize();
    Log.d(
        LOG_TAG,
        String.format("In onCreate() : Initialization finished [sJobManager = %s, sPreferencesHelper = %s]",
            String.valueOf(mJobManager), String.valueOf(mPreferencesHelper)));
  }

  private void initialize() {
    sInstance = this;
    mJobManager = new DefaultJobManager();
    mJobManager.start();
    mPreferencesHelper = new PreferencesHelper(this);
  }

  /*
   * (non-Javadoc)
   * @see android.app.Application#onTerminate()
   */
  @Override
  public void onTerminate() {
    super.onTerminate();
    Log.d(LOG_TAG, "In onTerminate()");
  }

  /*
   * (non-Javadoc)
   * @see android.app.Application#onConfigurationChanged(android.content.res.
   * Configuration)
   */
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Log.d(LOG_TAG, String.format("In onConfigurationChanged(Configuration) : %s", String.valueOf(newConfig)));
  }

  /*
   * (non-Javadoc)
   * @see android.app.Application#onLowMemory()
   */
  @Override
  public void onLowMemory() {
    super.onLowMemory();
    Log.d(LOG_TAG, "In onLowMemory()");
  }

  /**
   * @return the sInstace
   */
  public static Application getInstance() {
    return sInstance;
  }

  /**
   * @return the sJobManager
   */
  public JobManager getJobManager() {
    return mJobManager;
  }

  /**
   * @return the sPreferencesHelper
   */
  public PreferencesHelper getPreferencesHelper() {
    return mPreferencesHelper;
  }
}
